package com.epam.training.myspringioc;

import com.epam.training.myspringioc.factory.BeanFactory;
import com.epam.training.myspringioc.factory.XmlBeanFactory;
import com.epam.training.myspringioc.parsers.ParserTypes;
import com.epam.training.myspringioc.reader.XmlBeanDefinitionReader;
import com.epam.training.myspringioc.reader.XmlBeanDefinitionReaderImpl;

public class GenericXmlApplicationContext implements ApplicationContext {

	private final XmlBeanDefinitionReader reader;

	public GenericXmlApplicationContext() {
		reader = new XmlBeanDefinitionReaderImpl();
	}
	
	/**
	 * 
	 * @param reader
	 */
	public GenericXmlApplicationContext(XmlBeanDefinitionReader reader) {
		this.reader = reader;
	}

	public BeanFactory getBeanFactory() {
		return new XmlBeanFactory(reader.getBeanDefinition());
	}

	@Override
	public void setValidating(boolean validating) {
		reader.setValidating(validating);
	}

	@Override
	public void setParserType(ParserTypes parserType) {
		reader.setParserType(parserType);
	}

	@Override
	public void load(String xmlFileLocation) {
		reader.loadBeanDefinitions(xmlFileLocation);
	}
}
